package swings.panels;

import entity.CommonParam;
import entity.CommonRecord;
import swings.labels.HeaderLabel;
import swings.labels.LimpidLabel;
import swings.labels.ParamLabel;
import utils.ImageUtils;

import java.io.IOException;
import java.util.ArrayList;

/**
 * @version V1.0
 * @Title:
 * @Package
 * @Description:
 * @author: runoob
 * @date:
 */
public class SecretsPanel extends CommonPanel{

    private ParamLabel dataSecretLabel = new ParamLabel(40, 0, "dataSecret", "", "AES秘钥", this);
    private ParamLabel dataSecretIVLabel = new ParamLabel(70, 1, "dataSecretIV", "", "加密向量", this);
    private ParamLabel appSecretLabel = new ParamLabel(100, 2, "appSecret", "", "MD5秘钥", this);

    public SecretsPanel() throws IOException {
        HeaderLabel headerLabel = new HeaderLabel(5, "KEY", "VALUE", "DESCRIPTION");
//        dataSecretLabel.setUnEditable();
        dataSecretLabel.setKeyUneditable();
        dataSecretLabel.setDescriptionUneditable();
//        dataSecretIVLabel.setUnEditable();
        dataSecretIVLabel.setKeyUneditable();
        dataSecretIVLabel.setDescriptionUneditable();
//        dataSecretIVLabel.setUnEditable();
        appSecretLabel.setKeyUneditable();
        appSecretLabel.setDescriptionUneditable();
        this.add(dataSecretLabel);
        this.add(dataSecretIVLabel);
        this.add(appSecretLabel);
        this.add(headerLabel);
        this.setBounds(5,81,WorkPanel.width-10,WorkPanel.height/2-80);
        this.add(new LimpidLabel(ImageUtils.common,0, 0, WorkPanel.width-10, WorkPanel.height/2-80));
        this.setBorder(null);
    }

    public ArrayList<CommonParam> getData(){
        ArrayList<CommonParam> result = new ArrayList<>();
        CommonParam dataSecret = new CommonParam();
        dataSecret.setKey(dataSecretLabel.keyField.getText());
        dataSecret.setValue(dataSecretLabel.valueField.getText());
        dataSecret.setDescription(dataSecretLabel.descriptionField.getText());
        result.add(dataSecret);
        CommonParam dataSecretIV = new CommonParam();
        dataSecretIV.setKey(dataSecretIVLabel.keyField.getText());
        dataSecretIV.setValue(dataSecretIVLabel.valueField.getText());
        dataSecretIV.setDescription(dataSecretIVLabel.descriptionField.getText());
        result.add(dataSecretIV);
        CommonParam appSecret = new CommonParam();
        appSecret.setKey(appSecretLabel.keyField.getText());
        appSecret.setValue(appSecretLabel.valueField.getText());
        appSecret.setDescription(appSecretLabel.descriptionField.getText());
        result.add(appSecret);
        return result;
    }

    public void setData(CommonRecord commonRecord){
        dataSecretLabel.valueField.setText(commonRecord.getDataSecret());
        dataSecretIVLabel.valueField.setText(commonRecord.getDataSecretIV());
        appSecretLabel.valueField.setText(commonRecord.getAppSecret());
    }

}
